//参考文档 : https://github.com/tencentyun/cos-nodejs-sdk-v5/blob/master/demo/demo.js

export function uploadtocos(file, filename){
    var fs = require('fs');
    var path = require('path');
    var COS = require('cos-nodejs-sdk-v5');
    var SecretId = 'AKIDeN7Dq6OoO2kWLpt7V0Z7gCnTCyP3GTk2'; // 替换为用户的 SecretId
    var SecretKey = 'kcXVNMPWg9hbr7vz9KaLYhyKjZSN7vlc';    // 替换为用户的 SecretKey
    var Bucket = 'wkkk-1253981692';                        // 替换为用户操作的 Bucket
    var Region = 'ap-shanghai';                           // 替换为用户操作的 Region

    var cos = new COS({SecretId: SecretId, SecretKey: SecretKey});

    var filepath = path.resolve(__dirname, file.name);
    cos.putObject({
        Bucket: Bucket,
        Region: Region,
        Key: filename,
        Body: fs.createReadStream(filepath),
        ContentLength: fs.statSync(filepath).size,
        onProgress: function (progressData) {
            console.log(JSON.stringify(progressData));
        },
    }, function (err, data) {
        console.log(err || data);
    });
    return {'done':true};
}
